package com.example.ajaxdemo.controller;

import com.example.ajaxdemo.model.User;
import org.springframework.web.bind.annotation.*;

/**
 * @description: TODO
 * @author: uu
 * @data: 2023/7/13 下午 03:21
 * @version: v1.0
 */
@RestController
@CrossOrigin
public class UserController {
    // get请求
    @GetMapping("/user/query")
    public User queryUser(){
        User user = new User(1,"cms",23,"男");
        System.out.println(user);
        return user;
    }
    @GetMapping("/user/get")
    public String get(Integer id, String name){
        return id+name;
    }

    @PostMapping("/user/post")
    public String post(Integer id, String name){
        return id + name;
    }

    /***
     * @param @RequestBody: 从请求体中获取数据，转为形参的对象
     *  1. 请求头 Content-Type : application/json
     *  2. 发起的请求是post， 请求的数据格式是json格式
     * @param user
     * @return
     */
    @PostMapping("/user/json")
    public User json(@RequestBody User user){
        return user;
    }


    @PostMapping("/axios/post")
    public User axiosPost(@RequestBody User user){
        return user;
    }

}
